<!DOCTYPE HTML>
<?php
session_start();
if (!isset($_SESSION['login'])) {
    header('location:../vue/index.php');
}
date_default_timezone_set('Europe/Paris');
?>

<html>

    <head>
        <title>BLOG</title>
        <meta charset="utf8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
		<script src="http://tinymce.cachefly.net/4.1/tinymce.min.js"></script>
		<script>tinymce.init({
    selector: "textarea",
    setup: function (editor) {
        editor.on('change', function () {
            tinymce.triggerSave();
        });
    }
});</script>

        <style type="text/css">

            .content{
                margin:5% 10% 0 10%;
            }

            body{
                min-width:800px;
                width:auto!important;
                width:800px;
                height:5000px;
				background-image:url(../img/sharp_edge.png);
                background-repeat:repeat;
            }

            input{
                margin-bottom:5px;
            }

			.navbar{
				-webkit-box-shadow: 0px 4px 15px 0px rgba(0,0,0,0.75);
				-moz-box-shadow: 0px 4px 15px 0px rgba(0,0,0,0.75);
				box-shadow: 0px 4px 15px 0px rgba(0,0,0,0.75);
			}
			
            label{
                margin:0 5px 0 0;
				color:white;
            }

        </style>

    </head>

    <script type="text/javascript">

        function recupinput() {
            var myvar = document.getElementById('cat_new');
            document.location.href = "../controleur/ajouter_cat.php?cat_new=" + myvar.value;
        }

$(window).load(function(){
    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            
            reader.onload = function (e) {
                $('#blah').attr('src', e.target.result);
            }
            
            reader.readAsDataURL(input.files[0]);
        }
    }
    
    $("#imgInp").change(function(){
        readURL(this);
    });
}); 


		
    </script>



    <body>

        <?php include 'navBar.php'; ?>
            <fieldset style="margin:0 10%">
                <form method="POST" action="../controleur/ajouter_post.php" runat="server" enctype="multipart/form-data">
                    <select name="art_cat" class="form-control">
                        <?php
                        $myvar = new SQLBlog();
                        if ($var = $myvar->AfficherCategories()) {
                            foreach ($var as $line) {
                                echo "<option value=\"" . $line['id'] . "\">" . $line['nom'] . "</option>";
                            }
                        }
                        ?>
                    </select>
                    <input type="text" class="form-control" placeholder="Nouvelle Categorie" name="cat_new" id="cat_new" style="width:inherit;display:inline;margin:5px 0 30px 0;"/>
                    <button type="button" name="newcat" class="btn btn-primary btn-success" value="Ajouter" onclick="recupinput()"><span class="glyphicon glyphicon-plus"></span></button>
                    <input type="text" class="form-control" placeholder="Titre" name="art_titre" required/>
                    <textarea type="text" class="form-control" placeholder="Contenu" name="art_contenu" rows="20" required></textarea><br>
					<input type="file" id="imgInp" name="pj" accept=".jpg,.png,.gif,.jpeg" style="color:white;"/><br/>
					// <img id="blah" src="#" alt="Votre image" style="width:500px;"/><br/><br/>
                    <label>Post visible ?</label><input type="checkbox" name="art_actif"/><br/>
                    <label>Commentaire autorisés ?</label><input type="checkbox" name="art_comm"/><br/><br>
                    <input type="submit" name="valid_post" value="Sauvegarder" class="btn btn-primary btn-success"/>
                </form>
            </fieldset>
    </body>
	
	<?php include('footer.php'); ?>
</html>